package dao.Impl;

import dao.BaseDao;
import dao.flowerDao;
import entity.Flower;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class flowerDaoImpl extends BaseDao implements flowerDao {
    Flower flower=null;
    @Override
    public List<Flower> select() {
        String sql="SELECT id,name,anothername,property,price,production FROM flower";
        ResultSet rs=executeQuery(sql);
        List<Flower> list=new ArrayList<>();
        try {
            while (rs.next()){
            flower=new Flower();
            flower.setId(rs.getInt("id"));
            flower.setName(rs.getString("name"));
            flower.setAnothername(rs.getString("anothername"));
            flower.setProperty(rs.getString("property"));
            flower.setPrice(rs.getDouble("price"));
            flower.setProduction(rs.getString("production"));
            list.add(flower);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            closeAll(connection,pstmt,rs);
        }
        return list;
    }

    @Override
    public int add(String name, String anothername, String property, double price, String production) {
        String sql="insert into flower(name,anothername,property,price,production) values(?,?,?,?,?)";
        Object params[]={name,anothername,property,price,production};
        int hangshu=executeUpdate(sql,params);
        return hangshu;
    }
}
